package com.ethereal.servlet.Dao;

import com.ethereal.servlet.DatabaseUtil;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class UserDao {
    public Boolean login(HttpServletRequest req, HttpServletResponse resp){
        try {
            Connection conn = DatabaseUtil.getConnection();
            if (conn != null && conn.isClosed()){
                return false;
            }
            PreparedStatement pstmt = conn.prepareStatement("select * from user where user_name = ? and password = ?");
            pstmt.setString(1,req.getParameter("userName"));
            pstmt.setString(2,req.getParameter("password"));
            ResultSet rs = pstmt.executeQuery();
            return rs.next();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

}
